﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Framework;

namespace DomMgmtSystem.View
{
    public partial class HSYXRK_BASE : System.Web.UI.Page
    {
        #region 属性
        /// <summary>
        /// 
        /// </summary>
        private decimal TB_HSYXRK_BASE_ID
        {
            get
            {
                if (!string.IsNullOrEmpty(Request["baseID"]))
                    return Convert.ToDecimal(Request["baseID"]);
                return 0;
            }
        }

        /// <summary>
        /// 是否是添加
        /// </summary>
        public bool IsNew
        {
            get
            {
                if (ViewState["IsNew"] != null)
                    return Convert.ToBoolean(ViewState["IsNew"]);
                else
                    return this.GetRequestStr("isnew") != string.Empty;
            }

            set
            {
                ViewState["IsNew"] = value;
            }
        }

        /// <summary>
        /// 是否是浏览
        /// </summary>
        public bool IsView
        {
            get
            {
                return this.GetRequestStr("view") != string.Empty;
            }

        }
        /// <summary>
        /// 摄区编码
        /// </summary>
        public string CSQDH
        {
            get
            {
                return this.GetRequestStr("CSQDH");
            }
        }
        /// <summary>
        /// 摄区名称
        /// </summary>
        public string CSQMC
        {
            get
            {
                return this.GetRequestStr("CSQMC");
            }
        }
        /// <summary>
        /// 流水号
        /// </summary>
        public decimal LSH
        {
            get
            {
                if (this.GetRequestStr("LSH") != "")
                    return Convert.ToDecimal(this.GetRequestStr("LSH"));
                else
                    return 0;
            }
        }
        #endregion
        public string rows = "";
        public DataTable dtZd = new DataTable();
        public string reg = @"^(\d{4}-\d{1,2}-\d{1,2})$";
        public string regCJTNR = @"^((\d{4} \d{3}-\d{3},{0,1}，{0,1})+)$";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (TB_HSYXRK_BASE_ID == 0 && string.IsNullOrEmpty(CSQDH) && string.IsNullOrEmpty(CSQMC))
            {
                Response.Redirect("HSYXRK_BASE_List.aspx");
                return;
            }

            dtZd = DataAccess.ZHZD_T.GetList("").Tables[0];
            if (!IsPostBack)
                DataBind();

            if (Request.Params["view"] != null)
                ClientScript.RegisterStartupScript(typeof(Page), "a", "<script>ChangeToLabel();imghide();</script>");
            else
                txtRow.Text = string.Format(tr, "", dtZd.GetSelectString("硬盘套数", ""), "", "", "", dtZd.GetSelectString("数据位", ""), dtZd.GetSelectString("硬盘数据类型", ""), "", "", dtZd.GetSelectString("航摄仪型号", ""), "", "", "", "", "", "", "", "", dtZd.GetSelectString("存放层号", ""), dtZd.GetSelectString("存放列号", ""), "", "block", reg, regCJTNR);
        }

        protected void btnInHSRegisterSave_Click(object sender, EventArgs e)
        {
            List<Model.TB_HSYXRK_HD> hds = new List<Model.TB_HSYXRK_HD>();
            if (txthdlist.Text.Trim() != "")
                hds = JsonHelper.ParseFormJson<List<Model.TB_HSYXRK_HD>>(txthdlist.Text);

            Model.TB_HSYXRK_BASE hsBase = new Model.TB_HSYXRK_BASE();
            if (TB_HSYXRK_BASE_ID != 0)
                hsBase = DataAccess.TB_HSYXRK_BASE.GetModel(TB_HSYXRK_BASE_ID);
            else
                hsBase = new Model.TB_HSYXRK_BASE
               {
                   CHSDW = txtCHSDW.Text.Trim(),
                   CSQDH = lbCSQDH.Text,
                   CSQMC = lbCSQMC.Text.Trim(),
                   SQMJ = Convert.ToDecimal(txtSQMJ.Text.Trim()),
                   DTJSRQ = Convert.ToDateTime(txtDTJSRQ.Text.Trim()),
                   DTRKRQ = Convert.ToDateTime(txtDTRKRQ.Text.Trim()),
                   NYPS = string.IsNullOrEmpty(txtNYPS.Text.Trim()) ? 0 : Convert.ToDecimal(txtNYPS.Text.Trim()),
                   NYPTS = string.IsNullOrEmpty(ddlNYPTS.Text.Trim()) ? 0 : Convert.ToDecimal(ddlNYPTS.SelectedValue),
                   CREATE_DATE = DateTime.Now,
                   CREATE_USER = DomMgmtSystem.CommonCode.CurUser.CUSERNAME,
                   LSH = LSH// DataAccess.CommonExecute.GetLSH()
               };

            if (TB_HSYXRK_BASE_ID != 0)
            {
                DataAccess.TB_HSYXRK_BASE.Update(hsBase);
                DataAccess.TB_HSYXRK_HD.DeleteList(" NSQID=" + hsBase.NID);
            }
            else
                hsBase = DataAccess.TB_HSYXRK_BASE.Add(hsBase);

            Model.TB_XPH xph = new Model.TB_XPH();
            Model.TB_HSYXRK_HD hdBase = new Model.TB_HSYXRK_HD();
            foreach (Model.TB_HSYXRK_HD item in hds)
            {
                item.NSQID = hsBase.NID;
                if (string.IsNullOrEmpty(item.NJZBH))
                    item.NJZBH = DataAccess.CommonExecute.GetBarCode("1", "1");
                hdBase = DataAccess.TB_HSYXRK_HD.Add(item);
                DataAccess.TB_XPH.DeleteList(" NYP_NID=" + hdBase.NID);
                foreach (string val in item.CJTNR.Split(',', '，'))
                {
                    xph.NYP_NID = hdBase.NID;
                    xph.XPH_MAX = Convert.ToDecimal(val.Split(' ')[0] + val.Split(' ')[1].Split('-')[1]);
                    xph.XPH_MIN = Convert.ToDecimal(val.Split(' ')[0] + val.Split(' ')[1].Split('-')[0]);
                    DataAccess.TB_XPH.Add(xph);
                }
            }
            if (TB_HSYXRK_BASE_ID != 0)
                this.RedirectAfterInfo("编辑成功！", "HSYXRK_BASE_List.aspx");
            else
            {
                Model.TB_CHECK_HS check = DataAccess.TB_CHECK_HS.GetModel(lbCSQDH.Text.Trim());
                check.RKZT = 1;
                DataAccess.TB_CHECK_HS.Update(check);
                this.RedirectConfirmInfo("新增成功！是否继续新增？", "InCheckListHS.aspx", "HSYXRK_BASE.aspx");
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("HSYXRK_BASE_List.aspx");
        }
        public void DataBind()
        {
            int num = 1;
            DataTable dt = null;
            if (TB_HSYXRK_BASE_ID != 0)
            {
                btnBack.Visible = true;
                lbTitle.Text = IsView ? "查看航摄影像入库基本信息" : "编辑航摄影像入库基本信息";
                Model.TB_HSYXRK_BASE hsBase = DataAccess.TB_HSYXRK_BASE.GetModel(TB_HSYXRK_BASE_ID);

                lbCSQMC.Text = hsBase.CSQMC;
                lbCSQDH.Text = hsBase.CSQDH;
                txtSQMJ.Text = hsBase.SQMJ.Value.ToString();
                ddlNYPTS.SelectedValue = hsBase.NYPTS.ToString();
                txtDTJSRQ.Text = hsBase.DTJSRQ.Value.ToString("yyyy-MM-dd");
                txtDTRKRQ.Text = hsBase.DTRKRQ.Value.ToString("yyyy-MM-dd");
                txtNYPS.Text = hsBase.NYPS.ToString();
                txtCHSDW.Text = hsBase.CHSDW;

                dt = DataAccess.TB_HSYXRK_HD.GetList(" NSQID=" + TB_HSYXRK_BASE_ID).Tables[0];
                rows = "";
                foreach (DataRow item in dt.Rows)
                {
                    rows += string.Format(tr,
                        item["NID"],
                        dtZd.GetSelectString("硬盘套数", item["NYPTS"].ToString()),
                        item["CSN"],
                        item["NYPXH"],
                        item["CFQH"],
                        dtZd.GetSelectString("数据位", item["CSJW"].ToString()),
                        dtZd.GetSelectString("硬盘数据类型", item["SJLX"].ToString()),
                        Convert.ToDateTime(item["HSRQ"]) == DateTime.MinValue ? "" : Convert.ToDateTime(item["HSRQ"]).ToString("yyyy-MM-dd"),
                        item["HSFBL"],
                        dtZd.GetSelectString("航摄仪型号", item["HSYXH"].ToString()),
                        item["CJJ"],
                        item["FSJL"],
                        item["NSMPS"],
                        item["CHSBLC"],
                        item["SMFBL"],
                        item["CSMDW"],
                        item["CJTNR"],
                        item["NCFGH"],
                        dtZd.GetSelectString("存放层号", item["NCFCH"].ToString()),
                        dtZd.GetSelectString("存放列号", item["NYPTS"].ToString()),
                        item["C_BZ"],
                        "",
                        reg,
                        regCJTNR);
                    num++;
                }
            }
            else
            {
                lbCSQDH.Text = CSQDH;
                lbCSQMC.Text = CSQMC;
                lbTitle.Text = "新增航摄影像入库基本信息";
                dt = DataAccess.TB_CHECK.GetList(" STATE=0 ").Tables[0];
                rows = string.Format(tr, "", dtZd.GetSelectString("硬盘套数", ""), "", "", "", dtZd.GetSelectString("数据位", ""), dtZd.GetSelectString("硬盘数据类型", ""), "", "", dtZd.GetSelectString("航摄仪型号", ""), "", "", "", "", "", "", "", "", dtZd.GetSelectString("存放层号", ""), dtZd.GetSelectString("存放列号", ""), "", "block", reg, regCJTNR);
            }
        }


        #region
        string tr = @"                      <tr style='display:{21};'>
                        <td style='display: none'>
                            <input name='NID' type='text' value='{0}' style='width: 50px' />
                        </td>
                        <td>
                            <select name='NYPTS' style='width: 100px' isnull='False' fieldtype='decimal'>
                               {1}
                            </select>
                        </td>
                        <td>
                            <input name='CSN' type='text' style='width: 100px' value='{2}' fieldtype='nvarchar' isnull='False'/>
                        </td>
                        <td>
                            <input name='NYPXH' type='text' value='{3}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
                            <input name='CFQH' type='text' value='{4}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
                            <select name='CSJW' style='width: 100px' isnull='False' fieldtype='decimal'>
                                {5}
                                <!--<option value='8bit'>8bit</option>
                                <option value='12bit'>12bit</option>-->
                            </select>
                        </td>
                        <td>
                            <select name='SJLX' style='width: 150px' isnull='False' fieldtype='decimal'>
                                {6}
                                <!--<option value='1'>真彩色、黑白、彩红外</option>
                                <option value='2'>真彩色</option>
                                <option value='3'>雷达</option>
                                <option value='4'>胶片</option>-->
                            </select>
                        </td>
                        <td>
                            <div name='datetimepicker' class='input-append date'>
                                <input name='HSRQ' type='text' value='{7}' style='width: 100px' fieldtype='nvarchar' regex='{22}' isnull='False'/><span
                                    class='add-on'><i data-time-icon='icon-time' data-date-icon='icon-calendar'></i>
                                </span>
                            </div>
                            
                        </td>
                        <td>
                            <input name='HSFBL' type='text' value='{8}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
                            <select name='HSYXH' style='width: 100px' isnull='False' fieldtype='decimal'>
                                {9}
                                <!--<option value='1'>ADS40</option>
                                <option value='2'>ADS80</option>
                                <option value='3'>ALS70</option>
                                <option value='4'>Canon 5D Mark Ⅱ</option>
                                <option value='5'>DMC</option>
                                <option value='6'>DMC II</option>
                                <option value='7'>LMK</option>
                                <option value='8'>Pleiades</option>
                                <option value='9'>RC-10</option>
                                <option value='10'>RC-20</option>
                                <option value='11'>RC-10A</option>
                                <option value='12'>RC-30</option>
                                <option value='13'>RMK</option>
                                <option value='14'>RMKTOP</option>
                                <option value='15'>SWDC-4</option>
                                <option value='16'>SWDC-4A</option>
                                <option value='17'>SWDC</option>
                                <option value='18'>UCD</option>
                                <option value='19'>UCE</option>
                                <option value='20'>UCLP</option>
                                <option value='21'>UCX</option>
                                <option value='22'>UCXp</option>
                                <option value='23'>UCXp wa</option>
                                <option value='24'>机载雷达</option>-->
                            </select>
                        </td>
                        <td>
                            <input name='CJJ' type='text' value='{10}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
                            <input name='FSJL' type='text' value='{11}' style='width: 100px' fieldtype='decimal'/>
                        </td>
                        <td>
                            <input name='NSMPS' type='text' value='{12}' style='width: 100px' fieldtype='int'/>
                        </td>
                        <td>
                            <input name='CHSBLC' type='text' value='{13}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
                            <input name='SMFBL' type='text' value='{14}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
                            <input name='CSMDW' type='text' value='{15}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
                            <input name='CJTNR' type='text' value='{16}' style='width: 100px' fieldtype='nvarchar' isnull='False' regex='{23}' Msg='清输入正确格式！'/>
                        </td>
                        <td>
                            <input name='NCFGH' type='text' value='{17}' style='width: 50px' fieldtype='int'  isnull='False'/>
                        </td>
                        <td>
                            <select name='NCFCH' style='width: 60px' isnull='False' fieldtype='decimal'>
                                {18}
                                <!--<option value='1'>1</option>
                                <option value='2'>2</option>
                                <option value='3'>3</option>
                                <option value='4'>4</option>
                                <option value='5'>5</option>
                                <option value='6'>6</option>
                                <option value='7'>7</option>
                                <option value='8'>8</option>
                                <option value='9'>9</option>-->
                            </select>
                        </td>
                        <td>
                            <select name='NYPTS' style='width: 60px' isnull='False' fieldtype='decimal'>
                                {19}
                                <!--<option value='1'>1</option>
                                <option value='2'>2</option>
                                <option value='3'>3</option>
                                <option value='4'>4</option>
                                <option value='5'>5</option>
                                <option value='6'>6</option>
                                <option value='7'>7</option>
                                <option value='8'>8</option>
                                <option value='9'>9</option>-->
                            </select>
                        </td>
                        <td>
                            <input name='C_BZ' type='text' value='{20}' style='width: 100px' fieldtype='nvarchar'/>
                        </td>
                        <td>
<A onclick='javascript:delrow(this)' style='cursor: pointer'><IMG style='BORDER-TOP: 0px; BORDER-RIGHT: 0px; RIGHT: 5px; BORDER-BOTTOM: 0px; FLOAT: right; BORDER-LEFT: 0px' src='../images/del.gif'>
                        </td>
                    </tr>";
        #endregion
    }
}